package com.example.mobile2021606145zbq0401;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

 // private TextView tvMainTitle;
  private ImageView ivMainLight;
  private Button btnMainLightOn;
  private Button btnMainLightOff;
  private Button btnMainFan;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        btnMainLightOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainLight.setImageResource(R.drawable.on_png);
            }
        });
        btnMainLightOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ivMainLight.setImageResource(R.drawable.off_png);
            }
        });
        btnMainFan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ivMainLight.getTag().equals("fan_off"))
                {
                    ivMainLight.setImageResource(R.drawable.fan_on);
                    ivMainLight.setTag("fan_on");
                } else {
                    ivMainLight.setImageResource(R.drawable.fan_off);
                    ivMainLight.setTag("fan_off");

                }
            }
        });



    }

    private void initView() {
      //  tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        ivMainLight = (ImageView) findViewById(R.id.iv_main_light);
        btnMainLightOn = (Button) findViewById(R.id.btn_main_lightOn);
       btnMainLightOff = (Button) findViewById(R.id.btn_main_lightOff);
        btnMainFan = (Button) findViewById(R.id.btn_main_fan);
    }
}